package Test;

import Ctr.SupplierCtr;
import DB.SupplierDB;
import Model.Supplier;
import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.fail;

public class SupplierCtrTest {
    @Test
    public void testInsertSupplier() throws Exception {

        SupplierCtr supplierCtr = new SupplierCtr();
        supplierCtr.insertSupplier(500, "SupplierTest", "Test addrese", "Danmark", 123123123, "asd@asd.dk");

        if (supplierCtr.findSupplier(500).getId() == 500) {
            System.out.println("Insert successful");
        }
        else {
            fail("Insert not successful");
        }
    }

    @Test
    public void testFindSupplier() throws Exception {
        SupplierCtr supplierCtr = new SupplierCtr();

        int find = 4;

        Supplier supplier = supplierCtr.findSupplier(find);

        if (supplier != null) {
            System.out.println(
                    supplier.getId() + " " +
                            supplier.getName() + " " +
                            supplier.getAddress() + " " +
                            supplier.getCountry() + " " +
                            supplier.getPhoneNo() + " " +
                            supplier.getEmail());
        }
        else {
            fail("Error finding supplier - supplier is null");
        }
    }

    @Test
    public void testGetAllSuppliers() throws Exception {

        SupplierCtr supplierCtr = new SupplierCtr();

        ArrayList<Supplier> supplierArrayList;

        supplierArrayList = supplierCtr.getAllSuppliers(false);

        if (supplierArrayList != null) {
            System.out.println("Getting suppliers success!");

            System.out.println(supplierArrayList.size());
        }
        else {
            fail("Supplier arraylist is null - failed");
        }

    }

    @Test
    public void testUpdateSupplier() throws Exception {

    }

    @Test
    public void testDeleteSupplier() throws Exception {

    }
}
